<template>
<div class="cover_detail">
<el-button type="primary" class="goback_btn" @click="goback"> 返回 </el-button>
<el-form ref="form" :model="form" label-width="100px" class="thcat_form"  :loading="table_loading" :rules="rules">

   <el-form-item label="敏感字" prop="title">
      <el-input v-model="form.title" :disabled="false"></el-input>
  </el-form-item>
  
   <el-form-item label="状态" prop="status">
       <el-select v-model="form.status" placeholder="请选状态" prop="status">
        <el-option label="禁用" value="1"></el-option>
        <el-option label="正常" value="0"></el-option>
     </el-select>
   </el-form-item>

  <el-button type="success" class="goback_btn" @click="upload">提交</el-button>
</el-form>
</div>
</template>
<script>
import { CreateMgz, updateMgz } from '@/api/system/mgz'
import Auth from '@/mock/Auth.js'
import moment from 'moment'
moment.lang('zh-cn')
import PictureView from 'vue-simple-picture-preview'
const log = this.log
export default {
  data() {
    return {
      status: [{ name: '审核失败', value: 0 }, { name: '审核成功', value: 3 }],
      dialogFormVisible: false,
      form: {
        title: null,
        status: '1'
      },
      show_status: [
        {
          status: '禁用',
          val: 0
        },
        {
          status: '正常',
          val: 1
        }
      ],
      upload_form: {
        approvalStatus: '',
        feedback: ' ',
        id: '',
        userId: ''
      },
      show_report: false,
      table_loading: false,
      rules: {
        status: [{ required: true, message: '请选择状态', trigger: 'change' }],
        title: [{ required: true, message: '请输入敏感字', trigger: 'blur' }],
        approvalStatus: [
          { required: true, message: '请选择状态', trigger: 'change' }
        ],
        feedback: [
          { required: true, message: '请输入反馈', trigger: 'blur' }
        ]
      }
    }
  },
  components: {
    PictureView
  },
  watch: {
    'upload_form.approvalStatus': function(val) {
      console.log('show_report')
      console.log(val)
      if (val === 0) {
        this.show_report = true
      } else {
        this.show_report = false
      }
    },
    lastName: function(val) {
      this.fullName = this.firstName + ' ' + val
    }
  },
  computed: {
    status_t: {
      get: function() {
        if (this.form.val == 1) { return '正常' } else {
          return '禁用'
        }
      },
      // setter
      set: function(newValue) {
        console.log('newValue++++++++++++++++++++++++++++++')
        console.log(newValue)
        if (newValue == 1) { this.form.status = '正常' } else {
          this.form.status = '禁用'
        }
      }
    },
    updateTime_t: function() {
      const temp = new Date(this.form.updateTime).getTime()
      return moment(temp).format('MMMM Do YYYY, h:mm:ss a')
    },
    reviewTime_t: function() {
      const temp = new Date(this.form.reviewTime).getTime()
      return moment(temp).format('MMMM Do YYYY, h:mm:ss a')
    },
    formateTime_t: function(val) {
      const temp = new Date(this.form.updateTime).getTime()
      return moment(temp).format('MMMM Do YYYY, h:mm:ss a')
    },
    birthday_t: function() {
      const temp = new Date(this.form.birthday).getTime()
      this.form.birthday = moment(temp).format('MMMM Do YYYY, h:mm:ss a')
      return moment(temp).format('MMMM Do YYYY, h:mm:ss a')
    },
    approvalStatus_t: function() {
      if (this.form.approvalStatus == 0) {
        return '审核失败'
      } else if (this.form.approvalStatus == 1) {
        return '提交审核'
      } else if (this.form.approvalStatus == 2) {
        return '审核中'
      } else if (this.form.approvalStatus == 3) {
        return '审核成功'
      }
      // return this.form.approvalStatus
    }
  },
  created() {
    this.table_loading = true
    this.$nextTick(() => {
      const form = JSON.parse(this.$route.query.edit_msg)
      // 没有传值 就是edit
      console.log('form+++++++++++++++++++++++++++++++++')
      console.log(form)
      // this.$route.query.show ? form.disabled = true : form.disabled = false
      this.form = form
    })
  },
  methods: {
    onSubmit() {
      console.log('submit!')
    },
    show_upload() {
      this.dialogFormVisible = true
    },
    upload() {
      this.$refs['form'].validate(valid => {
        this.table_loading = true
        if (valid) {
          // Object.assign(this.upload_form, temp_form)
          // tempData.timestamp = +new Date(tempData.timestamp) // change Thu Nov 30 2017 16:41:05 GMT+0800 (CST) to 1512031311464
          updateMgz(this.form).then((e) => {
            this.table_loading = false
            this.log(e)
            if (e.data.code === 200) {
              this.$notify({
                title: '成功',
                message: '更新成功',
                type: 'success',
                duration: 2000,
                onClose: () => {
                  this.goback()
                }
              })
            } else {
              this.$message.error(e.data.msg)
            }
          }).catch((e) => {
            this.$message.error(e)
            this.table_loading = false
          })
        }
      })
    }

  }
}
</script>
<style lang="scss" scoped>
    .cover_detail{
      width: 100%;
      
    }
    .thcat_form{
      margin-top: 20px;
      width:50%;
    }
</style>
